-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathNewUserExample.py
More file actions
39 lines (28 loc) · 1.01 KB
/
NewUserExample.py
File metadata and controls
39 lines (28 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
from pysafeguard import *
import json
# The appliance host name or IP address
hostName = ''
# The user name for password authentication
userName = ''
# The password for password authentication
password = ''
# Path to the trusted root ca of the appliance
caFile = ''
user = {
'PrimaryAuthenticationProvider': { 'Id': -1 },
'Name': 'MyNewUser'
}
newuserpassword = 'MyNewUser123'
print('Connecting to Safeguard')
connection = PySafeguardConnection(hostName, caFile)
print('Logging in')
connection.connect_password(userName, password)
print('Creating new user')
result = connection.invoke(HttpMethods.POST, Services.CORE, 'Users', body=user).json()
# Gets the ID of newly created user
userId = result.get('Id')
print('Creating password for user')
connection.invoke(HttpMethods.PUT, Services.CORE, f'Users/{userId}/Password', body=newuserpassword)
print('Getting newly created user')
result = connection.invoke(HttpMethods.GET, Services.CORE, f'Users/{userId}')
print(json.dumps(result.json(),indent=2,sort_keys=True))